package com.apexwear.apexutils.dialog;

import android.app.Dialog;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothClass;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatButton;

import com.apexwear.apexutils.R;
import com.apexwear.apexutils.api.OnPositiveClickListener;
import com.apexwear.apexutils.utils.ShowToast;

public class ChangeMacDialog extends Dialog {
    OnPositiveClickListener onPositiveClickListener;
    Context mContext;

    public ChangeMacDialog(@NonNull Context context, OnPositiveClickListener onPositiveClickListener) {
        super(context, R.style.waiteDialog);
        mContext = context;
        this.onPositiveClickListener = onPositiveClickListener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        View dialogView = LayoutInflater.from(mContext).inflate(R.layout.dialog_change_mac, null, false);
        setContentView(dialogView);
        setCancelable(true);
        setCanceledOnTouchOutside(true);
        EditText inputText = dialogView.findViewById(R.id.input_mac);
        AppCompatButton changeButton = dialogView.findViewById(R.id.sure);
        AppCompatButton cancelButton = dialogView.findViewById(R.id.cancel);
        changeButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String newMac = inputText.getText().toString();
                if (TextUtils.isEmpty(newMac) || newMac.length() < 6) {
                    return;
                }
                if (onPositiveClickListener != null) {
                    onPositiveClickListener.clickButton(newMac.toUpperCase());
                }
                dismiss();
            }
        });
        cancelButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

    }

    public void destroyDialog() {
        mContext = null;
        dismiss();
        onPositiveClickListener = null;
    }
}
